package cn.gson.springboot.controller;

import cn.gson.springboot.model.pojos.Storage;
import cn.gson.springboot.model.service.StorageService;
import cn.gson.springboot.model.vo.StorageVo;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class StorageController {
    @Autowired
    StorageService stoService;

    //入库集合分页
    @RequestMapping("/sto-list")
    @ResponseBody
    public Map<String,Object> selectStorage(Integer page, Integer size, Integer status, Integer warId,String stoTheme){
        Page<Object> objects = PageHelper.startPage(page, size);
        List<Storage> sto = stoService.selectStorage(status, warId,stoTheme);
        Map<String,Object> map = new HashMap<>();
        map.put("rows",sto);
        map.put("total",objects.getTotal());
        return map;
    }
    //按id查询
    @RequestMapping("/sto-id")
    @ResponseBody
    public Storage selectStorageId(Integer stoId){
        Storage storage = stoService.selectStorageById(stoId);
        return storage;
    }
    //按采购单id查询
    @RequestMapping("/sto-pur-list")
    @ResponseBody
    public List<Storage> selectStoragePurIdList(Integer purId){
        List<Storage> sto = stoService.selectStorageByPurId(purId);
        return sto;
    }

    @PostMapping("/save-storage")
    @ResponseBody
    public Integer saveStorage(@RequestBody StorageVo vo){
       return stoService.saveStorage(vo);
    }
    @PostMapping("/delete-storage")
    @ResponseBody
    public void deleteStorage(@RequestParam(value = "stoId") Integer stoId){
        stoService.deleteStorage(stoId);
    }
}
